package com.changgou.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * <dl>
 * <dd>描述: ~节点业务逻辑实现</dd>
 * <dd>创建时间：  10:35 2020/3/30</dd>
 * <dd>创建人： zz</dd>
 * <dt>版本历史: </dt>
 * <pre>
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2020/3/30      guodong       1.0        1.0 Version
 * </pre>
 * </dl>
 */
@Component
public class IpFilter implements GlobalFilter,Ordered{

    private Logger log = LoggerFactory.getLogger(IpFilter.class);

    /*
        ip地址日志记录 交给风控大数据部门研究  C:\Windows\System32\Drivers\etc
     */
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        String hostName = exchange.getRequest().getRemoteAddress().getHostName();
        log.info("经过ip过滤器 ip地址是： {}", hostName);
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
